import { create, update, remove, query } from '../../../../../../framework/service/index';
import { ToastTips } from '../../../../../../common/toastTips/tosat';
import { routerRedux } from 'dva/router';

export default {

  namespace: 'commentPartTime',

  state: {
    data: [],
    list: {},
    applicationId:''
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if(location.pathname === '/comment-part-time') {
          const applicationId = location.query.id;
          // console.log('jobId', applicationId);
          dispatch({
            type: 'querySuccess',
            payload: {
              applicationId
            }
          })
        }
      })
    },
  },

  effects: {
    *postCommentContent({ payload }, { call, put, select }) {

      // console.log('payload', JSON.stringify(payload));

      const { code, data, message } = yield call(create, `/api/job/job-comment`, payload);

      // console.log('code', JSON.stringify(code));
      // console.log('data', JSON.stringify(data));
      // console.log('message', JSON.stringify(message));

      if (code === 200) {
        ToastTips('发送成功', 1500, null);
        yield put(routerRedux.goBack())
      }else{
        ToastTips('发送失败', 1500, null);
      }
    },
  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
